package com.ykdl.member.kid.marketcard;

import net.wxxr.dataparse.model.DataParseError;
import net.wxxr.dataparse.model.DataState;
import net.wxxr.http.interfaces.ITag;
import net.wxxr.http.request.HttpBaseRequest;
import oauth.signpost.http.HttpParameters;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.ykdl.member.constant.KidConfig;
import com.ykdl.member.kid.R;
import com.ykdl.member.kid.beans.GetUser_ScoreBean;
import com.ykdl.member.kid.gears.BaseScreen;
import com.ykdl.net.manager.TaskManager;
import com.ykdl.net.manager.Wxxr;

public class ChangeStateActivity extends BaseScreen implements OnClickListener{
	
	private TextView yunqi,baby,children;
	private GetUser_ScoreBean bean;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setTopTitle("更改状态", 0, R.drawable.back_bg, new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		}, 0, 0, null, 0);
		setContent(R.layout.activity_changestate);
		getData();
		initView();
	}
	
	private void initView() {
		// TODO Auto-generated method stub
		yunqi=(TextView) findViewById(R.id.yunqi);
		yunqi.setOnClickListener(this);
		baby=(TextView) findViewById(R.id.baby);
		baby.setOnClickListener(this);
		children=(TextView) findViewById(R.id.children);
		children.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent intent=new Intent(mContext, PersonalDataActivity.class);
		if(null!=bean){
			intent.putExtra("GetUser_ScoreBean", bean);
		}
		switch (v.getId()) {
		case R.id.yunqi:
			intent.putExtra("STATE", 1);
			startActivity(intent);
			break;
		case R.id.children:
			intent.putExtra("STATE", 3);
			startActivity(intent);
			break;
		case R.id.baby:
			intent.putExtra("STATE", 2);	
			startActivity(intent);
			break;
		default:
			break;
		}
	}
	
	public void getData() {
		showProgress("正在加载中,请稍等...");
		String pageurl = KidConfig.GET_MYSELF;
		HttpParameters parameterss = new HttpParameters();
		HttpBaseRequest request = Wxxr.getInstance().getRequest(pageurl,
				parameterss, null);
		TaskManager.startHttpRequest(request, new getDataTag(),
				GetUser_ScoreBean.class);
	}

	class getDataTag implements ITag {

		@Override
		public void refreshUI(Object t, DataState ds) {
			// TODO Auto-generated method stub
			finishProgress();
			if (t instanceof GetUser_ScoreBean) {
				GetUser_ScoreBean beans = (GetUser_ScoreBean) t;
				bean=beans;
				if(bean!=null){
					if(bean.getActor_info().getStatus()==1){ //#c1c0c0
						yunqi.setTextColor(Color.parseColor("#c1c0c0"));
						children.setTextColor(Color.parseColor("#707070"));
						baby.setTextColor(Color.parseColor("#707070"));
					}else if(bean.getActor_info().getStatus()==3){
						children.setTextColor(Color.parseColor("#c1c0c0"));
						yunqi.setTextColor(Color.parseColor("#707070"));
						baby.setTextColor(Color.parseColor("#707070"));
					}else{
						baby.setTextColor(Color.parseColor("#c1c0c0"));
						yunqi.setTextColor(Color.parseColor("#707070"));
						children.setTextColor(Color.parseColor("#707070"));
					}
				}
			}
		}

		@Override
		public boolean refreshError(DataParseError parseError) {
			// TODO Auto-generated method stub
			finishProgress();
			Toast.makeText(mContext, "加载失败", 1).show();
			return false;
		}

		@Override
		public void refreshCancel() {
			// TODO Auto-generated method stub
		}
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		getData();
	}

}
